'use strict';


module.exports = mongoose => {
  return class {

    constructor(name, schema, indexes) {
      this._name = name;
      this._schema = schema;
      this._indexes = indexes;
    }


    get Model() {
      if (!this._mongoose) {
        const schema = new mongoose.Schema(this._schema);
        if (this._indexes instanceof Array) {
          for (const index of this._indexes) { schema.index(index); }
        }
        this._mongoose = mongoose.model(this._name, schema);
      }

      return this._mongoose;
    }

  };
};
